package mao.mashibing.reentrantlock;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Reentrantlock1 {
    Lock lock = new ReentrantLock(true);

    public void m1(){
        while (true){
            try {
                lock.lock();
                TimeUnit.SECONDS.sleep(1);
                System.out.println("m1..........");
            }catch (InterruptedException e){
                e.printStackTrace();
            }finally {
                lock.unlock();
            }
        }
    }
    
    public void m2(){
        while (true){
            try {
                lock.lock();
                TimeUnit.SECONDS.sleep(1);
                System.out.println("m2........");
            }catch (InterruptedException e){
                e.printStackTrace();
            }finally {
                lock.unlock();
            }
        }
    }

    public static void main(String[] args) {
        Reentrantlock1 rl = new Reentrantlock1();
        new Thread(rl::m1).start();
        new Thread(rl::m2).start();
    }


}
